﻿<ResourceDictionary x:Class="ICSharpCode.Data.Core.UI.UserControls.DatabaseTreeViewResources"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:ICSharpCode.Data.Core.UI.UserControls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="../MainDictionary.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <HierarchicalDataTemplate x:Key="StandardDataTemplate" ItemsSource="{Binding Path=Items}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <CheckBox x:Name="chkIsSelected" Margin="2" Click="chkStandardTemplateIsSelected_Click" Visibility="Collapsed" Tag="{Binding Path=Items}" />
            <TextBlock Margin="2" Text="{Binding Name}" />
        </Grid>
        <HierarchicalDataTemplate.Triggers>
            <DataTrigger Binding="{Binding ShowCheckBoxes, RelativeSource={RelativeSource AncestorType=TreeView}}" Value="True">
                <Setter Property="Visibility" TargetName="chkIsSelected" Value="Visible" />
            </DataTrigger>
        </HierarchicalDataTemplate.Triggers>
    </HierarchicalDataTemplate>
    <HierarchicalDataTemplate x:Key="DatabaseDataTemplate" ItemsSource="{Binding Path=Items}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <CheckBox x:Name="chkIsSelected" Margin="2" Click="chkStandardTemplateIsSelected_Click"
                IsChecked="{Binding IsSelected}" Visibility="Collapsed" Tag="{Binding Path=Items}" />
            <Image Grid.Column="1" Margin="2" Source="{StaticResource DatabaseImage}" Width="16" Height="16" />
            <TextBlock Grid.Column="2" Margin="2" Text="{Binding Name}" VerticalAlignment="Center" />
        </Grid>
        <HierarchicalDataTemplate.Triggers>
            <DataTrigger Binding="{Binding ShowCheckBoxes, RelativeSource={RelativeSource AncestorType=TreeView}}" Value="True">
                <Setter Property="Visibility" TargetName="chkIsSelected" Value="Visible" />
            </DataTrigger>
        </HierarchicalDataTemplate.Triggers>
    </HierarchicalDataTemplate>
    <HierarchicalDataTemplate x:Key="TableDataTemplate" ItemsSource="{Binding Path=Items}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <CheckBox x:Name="chkIsSelected" Margin="2" Click="chkStandardTemplateIsSelected_Click" 
                IsChecked="{Binding IsSelected}" Visibility="Collapsed" Tag="{Binding Path=Items}" />
            <Image Grid.Column="1" Margin="2" Source="{StaticResource DatabaseTableImage}" Width="16" Height="16" />
            <TextBlock Grid.Column="2" Margin="2" Text="{Binding Name}" VerticalAlignment="Center" PreviewMouseLeftButtonDown="DatabaseObject_PreviewMouseLeftButtonDown" />
        </Grid>
        <HierarchicalDataTemplate.Triggers>
            <DataTrigger Binding="{Binding ShowCheckBoxes, RelativeSource={RelativeSource AncestorType=TreeView}}" Value="True">
                <Setter Property="Visibility" TargetName="chkIsSelected" Value="Visible" />
            </DataTrigger>
            <DataTrigger Binding="{Binding HasKeyDefined}" Value="False">
                <Setter Property="IsEnabled" TargetName="chkIsSelected" Value="False" />
            </DataTrigger>
        </HierarchicalDataTemplate.Triggers>
    </HierarchicalDataTemplate>
    <DataTemplate x:Key="ColumnDataTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Image x:Name="imgColumn" Grid.Column="1" Margin="2" Source="{StaticResource TableImage}" Width="16" Height="16" />
            <TextBlock Grid.Column="2" Margin="2" Text="{Binding ColumnSummary}" VerticalAlignment="Center" PreviewMouseLeftButtonDown="DatabaseObject_PreviewMouseLeftButtonDown" />
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsForeignKey}" Value="True">
                <Setter TargetName="imgColumn" Property="Source" Value="{StaticResource TableForeignKeyImage}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsPrimaryKey}" Value="True">
                <Setter TargetName="imgColumn" Property="Source" Value="{StaticResource TableKeyImage}" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    <HierarchicalDataTemplate x:Key="ProcedureDataTemplate" ItemsSource="{Binding Path=Items}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <CheckBox x:Name="chkIsSelected" Margin="2" Click="chkStandardTemplateIsSelected_Click"
                IsChecked="{Binding IsSelected}" Visibility="Collapsed" Tag="{Binding Path=Items}" />
            <Image Grid.Column="1" Margin="2" Source="{StaticResource ProcedureImage}" Width="16" Height="16" />
            <TextBlock Grid.Column="2" Margin="2" Text="{Binding Name}" VerticalAlignment="Center" PreviewMouseLeftButtonDown="DatabaseObject_PreviewMouseLeftButtonDown" />
        </Grid>
        <HierarchicalDataTemplate.Triggers>
            <DataTrigger Binding="{Binding ShowCheckBoxes, RelativeSource={RelativeSource AncestorType=TreeView}}" Value="True">
                <Setter Property="Visibility" TargetName="chkIsSelected" Value="Visible" />
            </DataTrigger>
        </HierarchicalDataTemplate.Triggers>
    </HierarchicalDataTemplate>
    <DataTemplate x:Key="ProcedureParameterDataTemplate">
        <StackPanel Orientation="Horizontal">
            <TextBlock Margin="2,2,0,2" Text="@" VerticalAlignment="Center" PreviewMouseLeftButtonDown="DatabaseObject_PreviewMouseLeftButtonDown" />
            <TextBlock Margin="0,2,2,2" Text="{Binding Name}" VerticalAlignment="Center" PreviewMouseLeftButtonDown="DatabaseObject_PreviewMouseLeftButtonDown" />
        </StackPanel>
    </DataTemplate>

    <local:DatabaseTreeViewDataTemplateSelector x:Key="DatabaseTreeViewDataTemplateSelector" />
</ResourceDictionary>